Skip to content

Add protovalidate as alternative to protoc-gen-validate #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 15, 2025

Conversation

tstirrat15
Copy link
Contributor

@tstirrat15 tstirrat15 commented Nov 21, 2024

Description

I ran into this while looking into authzed-rb's implementation of validation. I hoped that it might solve that problem, but it turns out that there isn't a protovalidate implementation for ruby either (yet, I hope).

I think there's still value in bringing this in, though.

protoc-gen-validate is in maintenance mode: https://github.com/bufbuild/protoc-gen-validate?tab=readme-ov-file#-protoc-gen-validate-pgv

The library they want us to move to is protovalidate: https://github.com/bufbuild/protovalidate

This follows the steps in the migration guide to add annotations that are compatible with protovalidate and allow the downstream libs to use the protovalidate libs as desired.

Notes

The breaking change lint step is complaining, but I ran it locally and it's not code that we use directly or control:

➜  api git:(use-protovalidate-instead-of-protoc-gen-validate) buf breaking . --against https://github.com/authzed/api.git\#branch\=main
protoc-gen-openapiv2/options/openapiv2.proto:45:1:Previously present reserved range "[13]" on message "Swagger" is missing values: [13] were removed.
protoc-gen-openapiv2/options/openapiv2.proto:587:1:Previously present reserved range "[1]" on message "Tag" is missing values: [1] were removed.

It appears to be complaining about the proto provided by the grpc-gateway dep, and that version bump happened when I added the new dependency. I'm not particularly concerned about it breaking anything.

Changes

Notes

This does not remove support for protoc-gen-validate. We probably won't do that for a while yet. This should be a non-breaking change.

Testing

Review. See that our CI still passes.

@tstirrat15 tstirrat15 changed the title Use protovalidate instead of protoc gen validate Add protovalidate as alternative to protoc-gen-validate Nov 22, 2024
@tstirrat15 tstirrat15 force-pushed the use-protovalidate-instead-of-protoc-gen-validate branch from 5199e7b to 0f29d31 Compare March 12, 2025 22:09
@tstirrat15 tstirrat15 force-pushed the use-protovalidate-instead-of-protoc-gen-validate branch from bc7dbea to 6676de4 Compare March 13, 2025 16:37
Copy link

github-actions bot commented Mar 13, 2025

The latest Buf updates on your PR. Results from workflow Lint / lint (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed⏩ skippedApr 15, 2025, 10:00 PM

@tstirrat15 tstirrat15 added the Buf Skip Breaking Used to mark a breaking buf change as expected label Mar 13, 2025
josephschorr
josephschorr previously approved these changes Apr 15, 2025
Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

miparnisari
miparnisari previously approved these changes Apr 15, 2025
- uses: "actions/checkout@v3"
- uses: "bufbuild/buf-setup-action@v1.32.2"
- uses: "actions/checkout@v4"
- uses: "bufbuild/buf-setup-action@v1.47.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf-setup-action was deprecated in favor of buf-action: https://github.com/bufbuild/buf-setup-action#buf-setup-action

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm using it in the lint action. I can update this usage as well.

@@ -1,15 +1,21 @@
---
version: "v1"
version: "v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, did you use buf config migrate? https://buf.build/docs/migration-guides/migrate-v2-config-files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor Author

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committing

@@ -4,8 +4,8 @@ package authzed.api.materialize.v0;
import "authzed/api/v1/core.proto";

option go_package = "github.com/authzed/authzed-go/proto/authzed/api/materialize/v0";
option java_package = "com.authzed.api.materialize.v0";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes to imports are a part of running buf format

with:
version: "1.30.0"
github_token: "${{ github.token }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This authenticates our buf requests

@@ -1,7 +1,7 @@
---
repos:
- repo: "https://github.com/bufbuild/buf"
rev: "v1.6.0"
rev: "v1.47.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we're linting with a recent version of buf

@@ -1,15 +1,21 @@
---
version: "v1"
version: "v2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

- uses: "actions/checkout@v3"
- uses: "bufbuild/buf-setup-action@v1.32.2"
- uses: "actions/checkout@v4"
- uses: "bufbuild/buf-setup-action@v1.47.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm using it in the lint action. I can update this usage as well.

@tstirrat15 tstirrat15 dismissed stale reviews from miparnisari and josephschorr via 7ac2968 April 15, 2025 22:00
@tstirrat15 tstirrat15 force-pushed the use-protovalidate-instead-of-protoc-gen-validate branch from 6676de4 to 7ac2968 Compare April 15, 2025 22:00
@tstirrat15 tstirrat15 merged commit 0d17d5f into main Apr 15, 2025
3 checks passed
@tstirrat15 tstirrat15 deleted the use-protovalidate-instead-of-protoc-gen-validate branch April 15, 2025 22:25
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Buf Skip Breaking Used to mark a breaking buf change as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants